package com.sbpm.crmbpm.client.resources.templates;

import com.google.gwt.safehtml.shared.SafeHtml;
import com.sbpm.crmbpm.client.resources.css.PersonInfoCss;
import com.sbpm.crmbpm.shared.data.client.Person;
import com.sencha.gxt.core.client.XTemplates;
import com.sencha.gxt.core.client.util.Format;

@XTemplates.FormatterFactories(@XTemplates.FormatterFactory(factory = PersonInfoRenderer.ShortenFactory.class, name = "shorten"))
public interface PersonInfoRenderer extends XTemplates
{
    @XTemplate(source = "PersonInfo.html")
    public SafeHtml renderItem(Person person, PersonInfoCss.Style style);

    public static class Shorten implements XTemplates.Formatter<String>
    {

        private int length;

        public Shorten(int length) {
            this.length = length;
        }

        @Override
        public String format(String data) {
            return Format.ellipse( data, length );
        }
    }

    public static class ShortenFactory {
        public static Shorten getFormat(int length) {
            return new Shorten(length);
        }
    }


}

